package com.four.marketing.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.four.marketing.entity.Group;
import com.four.marketing.service.IGroupService;
import com.four.marketing.vo.GroupVo;
import com.guli.common.utils.R;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gs
 * @since 2021-12-16
 */
@RestController
@RequestMapping("/group")
public class GroupController {

    @Autowired
    private IGroupService groupService;

    /**
     *拼团商品店家开启
     * 获取拼团商品的id
     * @param id
     * @return
     */
    @PostMapping("/addGroup/{id}/{loginName}")
    public R addGroup(@PathVariable("id")Integer id,@PathVariable("loginName")String loginName){
        groupService.addGroup(id,loginName);
        return R.ok();
    }

    /**
     *
     * 拼团列表 模糊 分页
     * @param vo
     * @param size
     * @param page
     * @return
     */
    @PostMapping("/list")
    public IPage<Group> list(@RequestBody GroupVo vo,
                             @RequestParam(value = "page",defaultValue = "1")Integer page,
                             @RequestParam(value = "size",defaultValue = "3")Integer size){

        return groupService.groupList(vo,page,size);
    }

    /**
     * 拼团删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable Long id){

        try {
            groupService.deleteById(id);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 拼团详情
     *
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    public Group findById(@PathVariable Long id){

        return groupService.findById(id);
    }
}
